package top.hiai.service;

import com.jfinal.plugin.activerecord.Page;

import top.hiai.model.Comment;


/**
* @Author www.hiai.top
* @Email  goodsking@163.com
* @Message 更多资源尽在www.hiai.top,开发者：黄康权
* @Introduction 类的介绍
*/

public class CommentService {
	private Comment dao = new Comment().dao();
	
	/**
	 * 根据用户的ID遍历评价，用于用户个人中心，评论的管理
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	public Page<Comment> paginateGetComment(int pageNumber, int pageSize,int uid) {
		return dao.paginate(pageNumber, pageSize, "select t_comment.cid ,t_comment.comment_date ,t_comment.content,t_article.aid,t_article.name,t_user.username ", 
				" from t_article , t_user, t_comment "
				+ " where t_article.aid=t_comment.article_id and t_article.user_id='"+uid+"' and t_comment.user_id=t_user.uid  and t_comment.state=1 order by t_comment.comment_date DESC");	
	}
	/**
	 * 根据文章的ID遍历评论信息
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	public Page<Comment> paginateGetArticleId(int pageNumber, int pageSize,int aid) {
		return dao.paginate(pageNumber, pageSize, "select t_comment.comment_date ,t_comment.content,t_user.username,t_user.image_name ", 
				" from t_user, t_comment "
				+ " where t_comment.article_id=? and t_comment.user_id=t_user.uid  and t_comment.state=1 order by t_comment.comment_date DESC",aid);	
	}
    /**
     * 删除评论
     * @param aid
     */
    public void deleteById(int cid) {
        dao.deleteById(cid);
    }
	/**
	 * 网站后台遍历评论信息，显示所有的评论信息
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	public Page<Comment> paginateAdmin(int pageNumber, int pageSize,String s_name) {
		if(s_name != null){
			return dao.paginate(pageNumber, pageSize, "select t_comment.cid,t_comment.content,t_comment.comment_date,t_comment.state,t_article.name,t_user.username ", 
					"from  t_comment,t_user,t_article "
					+ "where t_comment.user_id=t_user.uid and t_comment.article_id=t_article.aid  and t_comment.content like '%"+s_name+"%' order by t_comment.comment_date DESC");
		}else{
			return dao.paginate(pageNumber, pageSize, "select t_comment.cid,t_comment.content,t_comment.comment_date,t_comment.state,t_article.name,t_user.username ", 
					"from  t_comment,t_user,t_article "
					+ "where t_comment.user_id=t_user.uid and t_comment.article_id=t_article.aid  order by t_comment.comment_date DESC");
		}
	}
    
}
